var windowName = "user";
var Page;
apiready = function(){
    // onWindowShow(function () {
    //     getInfo(Page)
    // })
    onWindowHide(function () {
        console.log(windowName + " hide")
    })
    console.log("index page is OK");
    Page = createVM("#Page",{
        //页面数据
        user:{
            id:"-",
            name:"-",
            phone:"-",
            pic:"-",
        }
        ,open:false
    },{
        //页面方法
        "init":function () {
            startPullDownRefresh()
            // getInfo(this)
            this.user = getLocData("cacheUser")
        }
        ,onPullDownRefresh:function () {
            startPullDownRefresh()
            getInfo(this)
        }
        ,logout:function () {
            apiGet("/app/User/Logout", {}, function () {
                goto('login')
            });
        }
        ,clearCache:function () {
            delAllLocData()
            goto('login')
        }
        , openLog: function () {
            if (this.open) {
                this.open = false
                delLocData("htmlLog");
            }else {
                this.open = true
                setLocData("htmlLog",{open:true});
            }
        }
    })
    Page.init()

}
function getInfo(_this) {
    apiGet("/app/user/home",{},function (res) {
        stopPullDownRefresh()
        logJson(res)
        // showToast(res.message)
        _this.user = res.data
        _this.user.pic = getAssetBaseUrl() + res.data.pic
        setLocData('cacheUser',_this.user)
    })
}

function updateWinData() {
    log("user showed")
    getInfo(Page)
}